package com.cloudm.technician.ui.modules.web

import android.os.Bundle
import com.cloudm.technician.R
import com.cloudm.technician.extensions.addFragmentToActivity
import com.cloudm.technician.ui.base.BaseActivity

/**
 * 作者: wesley
 * 时间: 2017/12/28
 * 描述: 网页模块的界面
 */
class WebActivity : BaseActivity(), WebFragment.OnTitleReceivedListener {

    private var url: String? = null
    private var fragment: WebFragment? = null

    override fun handleBundle(bundle: Bundle) {
        url = bundle.getString("url")
    }

    override fun initVariables() {

    }

    override fun initViews(savedInstanceState: Bundle?) {
        fragment = manager.findFragmentById(
                R.id.common_content) as? WebFragment ?: WebFragment.newInstance(url)
        fragment?.listener = this
        addFragmentToActivity(manager, fragment)
    }

    override fun initListener() {

    }

    override fun onBackPressed() {
        when (fragment?.canGoBack()) {
            true -> fragment?.goBack()
            else -> super.onBackPressed()
        }
    }

    override fun onTitleReceive(title: String) {
        headerTitleString = title
        displayHomeAsUpEnabled = true
    }
}